<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="日期" prop="roomName">
        <el-date-picker
          v-model="form.date"
          type="datetimerange"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="桌子">
        <el-select v-model="queryParams.deskId" placeholder="选择桌子" clearable size="small">
          <el-option
            v-for="dict in tabList"
            :key="dict.id"
            :label="dict.tablenumberId"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="员工姓名" prop="staffName" >
        <el-input
          v-model="queryParams.staffName"
          placeholder="请输入会员员工姓名"
          clearable
          size="small"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
      <el-table-column label="店铺" align="center" prop="deptName" />
      <el-table-column label="桌号" align="center" prop="tablenumberName" />
      <el-table-column label="会员" align="center" prop="memberName" />
      <el-table-column label="开桌费用" align="center" prop="money" />
      <el-table-column label="开桌时间" align="center" prop="startTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="结账时间" align="center" prop="incomeRefundTime" >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.incomeRefundTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column label="店员" align="center" prop="staffName" />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRoom, delRoom, addRoom, updateRoom, exportRoom } from "@/api/mahjong/room";

import {  getChangList } from "@/api/mahjong/desking";
import {stockpileList, tableBillingList} from "@/api/mahjong/stockpile";
import {parseTime} from "../../../utils/ruoyi";

export default {
  name: "Room",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 表格数据
      tableList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      tabList:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startTime:undefined,
        endTime: undefined
      },
      // 表单参数
      form: {
        date: ''
      },
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.getTableList();
  },
  methods: {
    parseTime,
    /** 查询房间列表 */
    getTableList(){
      getChangList().then(response => {
        this.tabList = response.data;

      });
    },
    getList() {
      this.loading = true;
      tableBillingList(this.queryParams).then(response => {
        this.tableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        roomName: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if(this.form.date){
        this.queryParams.startTime=this.form.date[0]
        this.queryParams.endTime=this.form.date[1]
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateRoom(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          } else {
            addRoom(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              } else {
                this.msgError(response.msg);
              }
            });
          }
        }
      });
    },
  }
};
</script>
